package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClazzCountData;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.JobCountData;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption getEmpJobData() {
        List<Map<String, Object>> list = empMapper.countEmpJobData();
        List<String> jobList = list.stream().map(dataMap -> dataMap.get("pos").toString()).toList();
        List<Integer> dataList = list.stream().map(dataMap -> (Integer) dataMap.get("total")).toList();
        return new JobOption(jobList, dataList);
    }

    public JobOption getEmpJobData2() {
        JobOption jobOption = new JobOption();
        List<JobCountData> jobCountDataList = empMapper.countEmpJobData2();

        List<String> jobList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();

        for (JobCountData jobCountData : jobCountDataList) {
            jobList.add(jobCountData.getJobName());
            dataList.add(jobCountData.getNum());
        }
        jobOption.setJobList(jobList);
        jobOption.setDataList(dataList);
        return jobOption;
    }

    @Override
    public List<Map> getEmpGenderData() {
        List<Map> mapList = empMapper.countEmpGenderData();
        return mapList;
    }

    @Override
    public ClazzOption getClazzData() {
        ClazzOption clazzOption = new ClazzOption();
        List<ClazzCountData> clazzCountData = studentMapper.countStudentClazzData();
        List<String> clazzList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();
        clazzCountData.forEach(data -> {
            clazzList.add(data.getClazzName());
            dataList.add(data.getNum());
        });
        clazzOption.setClazzList(clazzList);
        clazzOption.setDataList(dataList);
        return clazzOption;
    }

    @Override
    public List<Map<String, Object>> getDegreeData() {
        return studentMapper.countStudentDegreeData();
    }
}
